class Solution {
public:
	bool lemonadeChange(vector<int>& bills) {
		int sum = 0;
		int five = 0;
		int ten = 0;

		for (int i = 0; i < bills.size(); ++i)
		{
			if (bills[i] == 5)
			{
				five++;
			}
			else if (bills[i] == 10)
			{
				five--;
				ten++;
				if (five < 0)
				{
					return false;
				}
			}
			else if (bills[i] == 20)
			{
				int tmp = 15;
				while (tmp > 0)
				{
					if (ten == 0 && five == 0)
					{
						return false;
					}
					else if (ten > 0 && tmp == 15)
					{
						ten--;
						tmp -= 10;
					}
					else if (five > 0)
					{
						five--;
						tmp -= 5;
					}
					else
					{
						return false;
					}
				}
			}
		}
		return true;
	}
};